home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / graphic / rtnews.zip / RTNV5N3 < prev   
Internet Message Format  |  1992-09-13  |  40KB

  1. From nucsrl!news.acns.nwu.edu!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!rutgers!psinntp!psinntp!eye!erich Mon Sep  7 19:44:41 CDT 1992
  2. Article: 13391 of comp.graphics
  3. Path: nucsrl!news.acns.nwu.edu!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!rutgers!psinntp!psinntp!eye!erich
  4. From: erich@eye.com (Eric Haines)
  5. Newsgroups: comp.graphics
  6. Subject: Ray Tracing News, Volume 5, Number 3
  7. Summary: point in polygon revisited
  8. Message-ID: <1992Sep2.101609.9105@eye.com>
  9. Date: 2 Sep 92 14:16:09 GMT
  10. Sender: erich@eye.com (Eric Haines)
  11. Organization: 3D/EYE, Inc.  Ithaca, NY
  12. Lines: 1000
  13.  
  14.  
  15.  _ __                 ______                         _ __
  16. ' )  )                  /                           ' )  )
  17.  /--' __.  __  ,     --/ __  __.  _. o ____  _,      /  / _  , , , _
  18. /  \_(_/|_/ (_/_    (_/ / (_(_/|_(__<_/ / <_(_)_    /  (_</_(_(_/_/_)_
  19.              /                               /|
  20.             '                               |/
  21.  
  22.             "Light Makes Right"
  23.  
  24.              September 2, 1992
  25.             Volume 5, Number 3
  26.  
  27. Compiled by Eric Haines, 3D/Eye Inc, 2359 Triphammer Rd, Ithaca, NY 14850
  28.     erich@eye.com
  29. All contents are copyright (c) 1992 by the individual authors
  30. Archive locations: anonymous FTP at princeton.edu (128.112.128.1)
  31.     /pub/Graphics/RTNews, wuarchive.wustl.edu:/graphics/graphics/RTNews,
  32.     and many others.
  33. UUCP archive access: write Kory Hamzeh (quad.com!avatar!kory) for info.
  34.  
  35. Contents:
  36.     Introduction
  37.     Intersection Between a Line and a Polygon (UNDECIDABLE??), by Dave Baraff,
  38.     Tom Duff
  39.     Fastest Point in Polygon Test, by Aladdin Nassar, Philip Walden, Eric
  40.     Haines, Tom Dickens, Ron Capelli, Sundar Narasimhan, Christopher Jam,
  41.     and (last but not least) Stuart MacMartin
  42.     Polygon Intersection via Barycentric Coordinates, by Peter Shirley
  43.     Many-Sided Polygon Intersection, by Eric Haines, Benjamin Zhu
  44.     Code for Point in Polygon Intersectors, by Eric Haines
  45.  
  46. -------------------------------------------------------------------------------
  47.  
  48. Introduction
  49.  
  50. This special issue is dedicated to everyone's (well, at least my) favorite
  51. computer graphics FAQ:  how do you find if a given point is inside a polygon?
  52. John Griegg's FAQ posting points at _An Introduction to Ray Tracing_, edited
  53. by Andrew Glassner.  This issue speeds up that algorithm (count the crossings
  54. of a test ray), and hopefully lays to rest the idea of using the "sum the
  55. angles" algorithm.  Plus there's a little discussion of what to do for special
  56. cases such as triangles and complex polygons, and code for four different ways
  57. to do this test at the end of the issue.
  58.  
  59. -------------------------------------------------------------------------------
  60.  
  61. [To begin this issue, here is one of the better pieces of obfuscatory writing
  62. in the field of computer graphics.  Reprinted from RTNews8 - EAH]
  63.  
  64.  
  65. Intersection Between a Line and a Polygon (UNDECIDABLE??),
  66.     by Dave Baraff, Tom Duff
  67.  
  68.     From: deb@charisma.graphics.cornell.edu
  69.     Newsgroups: comp.graphics
  70.     Keywords: P, NP, Jordan curve separation, Ursyhon Metrization Theorem
  71.     Organization: Program of Computer Graphics
  72.  
  73. In article [...] ncsmith@ndsuvax.UUCP (Timothy Lyle Smith) writes:
  74. >
  75. >  I need to find a formula/algorithm to determine if a line intersects
  76. >  a polygon.  I would prefer a method that would do this in as little
  77. >  time as possible.  I need this for use in a forward raytracing
  78. >  program.
  79.  
  80. I think that this is a very difficult problem.  To start with, lines and
  81. polygons are semi-algebraic sets which both contain uncountable number of
  82. points.  Here are a few off-the-cuff ideas.
  83.  
  84. First, we need to check if the line and the polygon are separated.  Now, the
  85. Jordan curve separation theorem says that the polygon divides the plane into
  86. exactly two open (and thus non-compact) regions.  Thus, the line lies
  87. completely inside the polygon, the line lies completely outside the polygon,
  88. or possibly (but this will rarely happen) the line intersects the polyon.
  89.  
  90. Now, the phrasing of this question says "if a line intersects a polygon", so
  91. this is a decision problem.  One possibility (the decision model approach) is
  92. to reduce the question to some other (well known) problem Q, and then try to
  93. solve Q.  An answer to Q gives an answer to the original decision problem.
  94.  
  95. In recent years, many geometric problems have been successfully modeled in a
  96. new language called PostScript.  (See "PostScript Language", by Adobe Systems
  97. Incorporated, ISBN # 0-201-10179-3, co. 1985).
  98.  
  99. So, given a line L and a polygon P, we can write a PostScript program that
  100. draws the line L and the polygon P, and then "outputs" the answer.  By
  101. "output", we mean the program executes a command called "showpage", which
  102. actually prints a page of paper containing the line and the polygon.  A quick
  103. examination of the paper provides an answer to the reduced problem Q, and thus
  104. the original problem.
  105.  
  106. There are two small problems with this approach.
  107.  
  108.     (1) There is an infinite number of ways to encode L and P into the
  109.     reduced problem Q.  So, we will be forced to invoke the Axiom of
  110.     Choice (or equivalently, Zorn's Lemma).  But the use of the Axiom of
  111.     Choice is not regarded in a very serious light these days.
  112.  
  113.     (2) More importantly, the question arises as to whether or not the
  114.     PostScript program Q will actually output a piece of paper; or in
  115.     other words, will it halt?
  116.  
  117.     Now, PostScript is expressive enough to encode everything that a
  118.     Turing Machine might do; thus the halting problem (for PostScript) is
  119.     undecidable.  It is quite possible that the original problem will turn
  120.     out to be undecidable.
  121.  
  122.  
  123. I won't even begin to go into other difficulties, such as aliasing, finite
  124. precision and running out of ink, paper or both.
  125.  
  126. A couple of references might be:
  127.  
  128. 1. Principia Mathematica.  Newton, I.  Cambridge University Press, Cambridge,
  129.    England.  (Sorry, I don't have an ISBN# for this).
  130.  
  131. 2. An Introduction to Automata Theory, Languages, and Computation.  Hopcroft, J
  132.   and Ulman, J.
  133.  
  134. 3. The C Programming Language. Kernighan, B and Ritchie, D.
  135.  
  136. 4. A Tale of Two Cities. Dickens, C.
  137.  
  138. --------
  139.  
  140. From: td@alice.UUCP (Tom Duff)
  141. Summary: Overkill.
  142. Organization: AT&T Bell Laboratories, Murray Hill NJ
  143.  
  144. The situation is not nearly as bleak as Baraff suggests (he should know
  145. better, he's hung around The Labs for long enough).  By the well known
  146. Dobbin-Dullman reduction (see J. Dullman & D. Dobbin, J. Comp. Obfusc.
  147. 37,ii:  pp. 33-947, lemma 17(a)) line-polygon intersection can be reduced to
  148. Hamiltonian Circuit, without(!) the use of Grobner bases, so LPI (to coin an
  149. acronym) is probably only NP-complete.  Besides, Turing-completeness will no
  150. longer be a problem once our Cray-3 is delivered, since it will be able to
  151. complete an infinite loop in 4 milliseconds (with scatter-gather.)
  152.  
  153. --------
  154.  
  155. From: deb@svax.cs.cornell.edu (David Baraff)
  156.  
  157. Well, sure it's no worse than NP-complete, but that's ONLY if you restrict
  158. yourself to the case where the line satisfies a Lipschitz condition on its
  159. second derivative.  (I think there's an '89 SIGGRAPH paper from Caltech that
  160. deals with this).
  161.  
  162. -------------------------------------------------------------------------------
  163.  
  164. Fastest Point in Polygon Test, by Aladdin Nassar, Philip Walden, Eric Haines,
  165.     Tom Dickens, Ron Capelli, Sundar Narasimhan, Christopher Jam, and
  166.     (last but not least) Stuart MacMartin
  167.  
  168.  
  169. Aladdin Nassar asked a variant on the classic question:
  170.  
  171. What is the MOST EFFICIENT way to find if a point lies within a SIMPLE
  172. polygon given a set of vertices (in no particular order) and the point
  173. coordinate ?   Are there anonymous ftp sites with such canned functions
  174. instead of re-inventing the wheel.  Excuse me if that is a trivial question.
  175.  
  176. ----
  177.  
  178. Philip Walden (pwalden@hpcc01.corp.hp.com) replies:
  179.  
  180. Another alternative to using a test ray is to sum the arc angles from
  181. the vertices to the test point. If the sum is 2pi, the point is inside,
  182. if 0 it's outside. i.e.
  183.  
  184.     give a polygon with a set of vertices v[1:n] an test point p
  185.  
  186.     if (SUM i=1 to n (arcangle(v[i]->p->v[i+1])) > pi
  187.     then p is inside